// step.h
// Copyright (C) 2008 Sam Bateman
// samuel.bateman@gmail.com
//
// This file is part of DVD On Fire.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

//! @file step.h
//! @author Sam Bateman
//! @brief Header file for the Step class.

#ifndef _YBJ_DOF_STEP_H
#define _YBJ_DOF_STEP_H

#include <stdexcept>
#include <string>
#include <libdvdonfire/thread.h>
#include "data.h"

namespace dvdonfire
{
    namespace daemon
    {
        // class Step {{{
        //! @brief Base class for steps.
        //!
        //! Base class for steps of the conversion process.  This provides
        //! some useful functionality shared among steps and a way to report
        //! progress and errors while processing in a separate thread.
        class Step : public dvdonfire::lib::Runnable
        {
        public:
            // constructor and destructor
            Step(const std::string& name);
            virtual ~Step();

            // functions for steps to implement
            virtual void cleanup() {}
            virtual void doStep() = 0;
            virtual void start();
            virtual void stop();

            // logging convenience functions
            void logDebug(const std::string& message);
            void logInfo (const std::string& message);
            void logWarn (const std::string& message);
            void logError(const std::string& message);
            void logArgs (const std::string *args, size_t num_args);

            // functions for steps to use
            Data* getData();
            void  setProgress(float progress);
            bool  yield();

            // functions for steps to not use
            std::string getError() const;
            float       getProgress() const;
            bool        isDone() const;
            void        run();
            void        setData(Data *data);

        private:
            // implementation
            struct Impl;
            Impl *impl;
        };
        // }}}
        // class StepError {{{
        //! @brief Error reporting.
        //!
        //! Exception class for reporting errors within a running Step.
        class StepError : public std::runtime_error
        {
        public:
            // constructor
            StepError(const std::string& error)
            : std::runtime_error(error) {}
        };
        // }}}
    }
}

#endif  // _YBJ_DOF_STEP_H
